<?php

namespace services\models;

use Yii;

/**
 * This is the model class for table "tmall1.member_info".
 *
 * @property integer $uid
 * @property integer $member_group
 * @property integer $member_type
 * @property integer $lkt_uid
 * @property string $username
 * @property string $member_pass
 * @property string $true_name
 * @property string $cell
 * @property integer $cell_active
 * @property string $email
 * @property integer $email_active
 * @property integer $member_point
 * @property double $member_money
 * @property integer $vip_endtime
 * @property integer $is_vip
 * @property integer $is_autoemail
 * @property integer $is_autosms
 * @property string $salt
 * @property integer $addtime
 * @property integer $lastlogintime
 * @property integer $emailtime
 * @property string $firstsaledate
 * @property string $lastsaledate
 * @property integer $isnewyear
 */
class MemberInfoBestry extends \common\models\MemberInfoBestry
{


    //邮箱是否激活 1为激活
    public static $EMAIL_ACTIVE_SUCCESS = 1;
    //邮箱是否激活 未激活
    public static $EMAIL_ACTIVE_FAIL = 0;
    //邮箱是否激活 为已发送激活邮件
    public static $EMAIL_ACTIVE_SENT = -1;

    //手机已激活
    public static $CELL_ACTIVE_SUCCESS = 1;
    //手机未激活
    public static $CELL_ACTIVE_FAIL = 0;


    public function getOrderInfo()
    {
        return $this->hasMany(OrderInfo::className(), ['bestry_uid' => 'uid']);
    }


    /**
     * Property addtime initial value
     * @param bool $insert
     * @return bool
     */
    public function beforeSave($insert)
    {
        if ($insert) {
            $this->addtime = time();
        }
        return parent::beforeSave($insert);
    }


    public function getMemberInfo()
    {
        return $this->hasOne(MemberInfo::className(), ['member_no' => 'lkt_uid']);
    }


    public static function getMemberInfoFromCacheByBestryUid($bestry_uid, $keys)
    {
        return Yii::$app->redis->hmget(Yii::$app->params['memberCache'] .
            Yii::$app->redis->hget(Yii::$app->params['bUidToLktUid'], $bestry_uid), $keys);

    }


    /**
     * 通过bestry_uid 获取member_id
     * @param int $bestry_uid
     * @return int
     */
    public static function getMemberIdByBestryUid($bestry_uid)
    {
        $info = MemberInfoBestry::findOne(['uid' => $bestry_uid]);
        if (!$info) {
            return 0;
        }

        return (int)$info->lkt_uid;

    }


}
